package com.szholly.pro.watergas_server.ps.android.controller;

import java.util.Map;

import javax.servlet.ServletContext;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;

import com.szholly.pro.watergas_server.ps.android.common.ResultUtils;
import com.szholly.pro.watergas_server.ps.android.common.ValidUtils;
import com.szholly.pro.watergas_server.ps.android.service.IndustryWaterService;

/**
 * 工业废水
 * 
 * 2017/3/30 <br/>
 *
 * @author Joey Huang QQ:273179370）
 */
@Controller
@RequestMapping("/android/industry/water/*")
public class IndustryWaterControl implements ServletContextAware {
	public static final String LEVEL_COMPANY = "2";
	public static final String LEVEL_POINT = "3";
	public static final String LEVEL_TASK = "4";

	private final IndustryWaterService mService = IndustryWaterService.getInstance();
	
	@SuppressWarnings("unused")
	private ServletContext servletContext;
	
	@Override
	public void setServletContext(ServletContext arg0) {
		this.servletContext = arg0;
	}

	@RequestMapping("/getLevelData")
	@ResponseBody
	public String getLevelData(String token, String userId, String level, String companyCode, String pointCode, String fatherTaskTypeCode, String taskTypeCode, String taskCode, String data) {
		try {
			ValidUtils.validateToken(token);
			ValidUtils.hasText(userId, "用户ID不能为空");
			ValidUtils.hasText(level, "界面等级不能为空");
			if (LEVEL_COMPANY.equals(level)) {
				return ResultUtils.getToastResult(mService.getCompanyList());
			}else if (LEVEL_POINT.equals(level)) {
				return ResultUtils.getToastResult(mService.getPointList(companyCode));
			}else if (LEVEL_TASK.equals(level)) {
				return ResultUtils.getToastResult(mService.getTaskList(pointCode));
			}				
			throw new Exception("界面等级有误");
		} catch (Exception e) {
			return ResultUtils.getToastResult(e);
		}
	}

	@RequestMapping("/getOperationTaskInitData")
	@ResponseBody
	public String getOperationTaskInitData(String token, String userId, String level, String companyCode, String pointCode, String fatherTaskTypeCode, String taskTypeCode, String taskCode, String data) {
		try {
			ValidUtils.validateToken(token);
			ValidUtils.hasText(userId, "用户ID不能为空");
			ValidUtils.hasText(taskTypeCode, "任务类型编号为空");
			Map<String, Object> operationTaskInitData = mService.getTaskService(taskTypeCode).getOperationTaskInitData(userId, pointCode, taskCode);
			return ResultUtils.getToastResult(operationTaskInitData);
		} catch (Exception e) {
			return ResultUtils.getToastResult(e);
		}
	}
}
